# class A:
#     def __init__(self):
#         self.name = 'python'
#         self.age = '22'
# class B(A):
#     pass
# B1 = B()
# print(B1.age)
# print(B1.name)
# # python3开始不用区分经典类和新式类
# # 经典类
# class A():
#     pass
# class B(object):
#     pass
# # 从python3开始，任何方式定义类，都默认继承自系统的object类
# class AA:
#
#
# class BB():
# #     pass
# # class CC(object):
# # #     pass
# # # class
# # #员工表
# # class Staff:
# #     def __init__(self,name,age):
# #         self.name = name
# #         self.age = age
# #     def run(self):
# #         print(f'{self.name}跑步')
# #     def eat(self):
# #         print(f'{self.name}吃东西')
# # # 讲师类
# # class Lecturer(Staff):
# #     def teach(self):
# #         print('讲课')
# # #班主任类
# # class Headmaster(Staff):
# #     pass
# # lecturer = Lecturer('python',18)
# # lecturer.run()
# # lecturer.eat()
# # lecturer.teach()
# # master = Headmaster('gugu',100)
# # master.run()
# # master.eat()
# # dog  继承 Animal
# class Animal:
#     def __init__(self, name, age, color):
#         self.name = name
#         self.age = age
#         self.color = color
#
#     def call(self):
#         return '叫'
#
#     def run(self):
#         return '跑'
#
#
# class Dog(Animal):
#     pass
#
#
# dog = Dog('发财', 5, '黑色')
# print(dog.call())
# print(dog.run())
#
#
# # 多继承
# # 语法:
# # c 继承了 A , B
# class Person:
#     def __init__(self, name, age):
#         self.name = name
#         self.age = age
#
#     def talk(self):
#         print(f'说话')
#
#
# # class Pig:
# #     def call(self):
# #         print('猪叫')
# #
# #
# # class Larr(Person, Pig):
# #     pass
# #
# #
# # lp = Larr('佩奇', 5)
# # lp.talk()
# # lp.call()
# #
# #
# # class Goods:
# #     def __init__(self):
# #         self.name = '商品'
# #
# #     def fn(self):
# #         return self.name
# #
# #
# # # 定义phone类
# # class Phone(Goods):
# #     def __init__(self):
# #         self.name = '手机'
# #
# #     def fn(self):
# #         return self.name
# #
# #
# # phone1 = Phone()
# # print(phone1.fn())
# # # 定义goods
# # class Goods:
# #     def __init__(self, name, price):
# #         self.name = name
# #         self.price = price
# #
# #     def info(self):
# #         print(f'名字：{self.name}, 单价：{self.price}')
# #
# #
# # # 定义phone
# # class Phone(Goods):
# #     def __init__(self, name, price, brand, os):
# #         # 调用父类的__init__方法
# #         super().__init__(name, price)
# #         self.brand = brand
# #         self.os = os
# #
# #     def info(self):
# #         super().info()
# #         print(self.brand)
# #         print(self.os)
#
# #
# #
# # p1 = Phone('iPhone13', 1999, 'apple', 'ios')
# # p1.info()
# class Person:
#     def __init__(self, name, age):
#         self.name = name
#         self.__age = age
#
#     def get1(self):
#         return self.__age
#
#     def set_age(self, age):
#         if 1 < age < 200:
#             self.__age = age
#         else:
#             print('输入的年龄不合法')
#
#     def __fn(self):
#         print('fn')
#
#     def run_fn(self):
#         self.__fn()
#
#         # 类的外部
#         p1 = Person('hello', 18)
#         # 通过这种手段可以访问到私有成员
#         # print(p1._Person__age)
#
#         print(p1.name)
#         print(p1.get_age())
#         p1.set_age(-1)
#         print(p1.get_age())
#
#         # p1.__fn()   # 私有方法类的外部调用不到
#
#         # 私有成员不能在类的外部访问
#         # print(p1.__age)
#
#         # 在派生类中访问
#         class Teacher(Person):
#             pass
#
#         # t1 = Teacher('python', 12)
#         # print(t1.name)
#         # print(t1.__age)
#
#
# # TODO dir 查看对象上的属性和方法
# class A:
#     def __init__(self):
#         self.name = 'xxx'
#
#     def fn(self):
#         pass
#
#
# a = A()
# print(dir(a))
#
# # TODO isinstance  判断对象是类的实例
# print(isinstance(a, A))
# print(isinstance('abc', A))
# print(isinstance(True, bool))
# print(isinstance('abc', str))
# #动物类\
# class Animal:
#     def call(self):
#         print('动物叫')
# class Dog(Animal):
#     def call(self):
#         print('旺旺')
# class Cat(Animal):
#     def call(self):
#         print('喵喵')
# class Person(Animal):
#     pass
# dog = Dog()
# cat = Cat()
# dog.call()
# cat.call()
# #
# # do_call(Dog Dog())
#
#  # TODO
# try:
#     1/0
# except ZeroDivisionError:
#     # print('0不能作为除数使用')
#     #TODO
# try:
#     1/0
# except  NameError:
#     print('0不能/作为除数使用')
# try:
#     num = int(input('输入一个数字:'))
#     result = 1 / num
# except (ZeroDivisionError,ValueError):
# #     print('输入的数字不合法')
# # try:
# #     num = int(input('请输入一个数字:'))
# #     result = 1 / num
# # except ZeroDivisionError:
# #     print('输入的数字不能是0')
# # except ValueError:
# #     print('输入的数字不合法')
# try:
#     num = int(input("请输入数字"))
#     result = 1/num
#     print(result)
# except Exception as e:
#     print(e)
# try:
#     num1 = int(input('请输入数字'))
#     result1 = 1 / num1
#     print(num1)
# except:
# #     print('输入的数字不合法')
# try:
#     f = open('demo.txt', 'r', encoding= 'utf8')
# except: FileNotFoundError
#     f = open('demo.txt', 'w', encoding='utf8')
# else:
#     content = f.read()
#     print(content)
# finally:
#     print('finally执行了')
#     f.close()
#     try:
#         try:
#         result = 1 / int(input('num:'))
#          except ZeroDivisionError:
#         print('输入的数字不是0')
#   except NameError:
#         print('nameError')
class LenError(Exception):
    def __str__(self):
        return '长度不合法'
username = input('username:')
try:
    if len(username) >= 6 and len(username) <= 18:
        print('用户名合法')
    else:
        raise LenError()
except LenError as e:
    print(e)